﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Xml;
using System.Xml.Linq;
using System.Windows.Forms;
using System.Text;

namespace XMLMovieWebsite
{
    public partial class SreachMovie : System.Web.UI.Page
    {
        String getKey_Ten;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                getKey_Ten = (Request.QueryString["Ten"]);
                loadDulieuRaFileXML();
                layDulieuTuXML();

            }
        }


        public void loadDulieuRaFileXML()
        {
            try
            {
                string ConString = ConfigurationManager.ConnectionStrings["ConStringXml"].ConnectionString;
                string CMDString = " SELECT  * FROM movie_thao where  Ten like N'%" + getKey_Ten + "%' or Mota like N'%" + getKey_Ten + "%' or DaoDien like N'%"
                    + getKey_Ten + "%' or DienVien like N'%" + getKey_Ten + "%' or QuocGia like N'%" + getKey_Ten + "%' or TheLoai like N'%" + getKey_Ten
                    + "%' or DanhMuc like N'%" + getKey_Ten + "%'";
                SqlConnection con;
                SqlCommand cmd;
                SqlDataAdapter sda;
                DataTable dt;


                using (con = new SqlConnection(ConString))
                {
                    cmd = new SqlCommand(CMDString, con);
                    con.Open();
                    dt = new DataTable("Movie");
                    sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                    if (dt != null)
                    {

                        dt.WriteXml(Server.MapPath("~/App_Data/Sreach.xml"));
                    }
                    con.Close();

                }
            }
            catch (Exception)
            {

            }


        }
        public void layDulieuTuXML()
        {
            using (DataSet ds = new DataSet())
            {
                ds.ReadXml(Server.MapPath("~/App_Data/Sreach.xml"));
                //GridView1.DataSource = ds;
                //GridView1.DataBind();
                DataTable dt = new DataTable();
                dt = ds.Tables["Movie"];
                //Image1.ImageUrl =  dt.Rows[0][11].ToString();

                Test.DataSource = dt;
                Test.DataBind();

                try
                {
                    Paging.PageSize = 4;
                    Paging.DataSource = dt.DefaultView;
                    Paging.BindToControl = Test;
                    Test.DataSource = Paging.DataSourcePaged;
                }
                catch { }

            }
        }



    }
}